<?php

/**
 * ContactForm class.
 * ContactForm is the data structure for keeping
 * contact form data. It is used by the 'contact' action of 'SiteController'.
 */
class SearchPeopleForm extends CFormModel
{
	public $topic, $limit=10, $offset=0;
	
	/**
	 * Declares the validation rules.
	 */
	public function rules()
	{
		return array(
			array('topic, limit, offset', 'safe'),
		);
	}

	/**
	 * Declares customized attribute labels.
	 * If not declared here, an attribute would have a label that is
	 * the same as its name with the first letter in upper case.
	 */
	public function attributeLabels()
	{
		return array(
			'limit'=>'Limit',
		);
	}
	
	public function getResult() {
		$fb = new Facebook();
		$fb->init(array(
			'appId' => Yii::app()->params['fb_app_id'],
			'appSerect' => Yii::app()->params['fb_app_serect'],
			'email' => Yii::app()->params['fb_email'],
			'password' => Yii::app()->params['fb_pass'],
			'returnUrl' => urlencode(Yii::app()->createAbsoluteUrl('site/index')),
			'limit' => $this->limit
		));

		$result = array();
		switch($this->type) {
			case 1:	// group
				$result = $fb->findGroups($this->key, $this->offset);
				break;
				
			case 2: // page
				$result = $fb->findPages($this->key, $this->offset);
				break;
		}
		return $result;
	}
}